<template>
    <Image :src="u" v-for="u in avatarUrl" :key="u"></Image>
    <Upload
      :format="['jpg', 'jpeg', 'png']"
      :max-size="2048"
      multiple
      type="drag"
      action="https://upload-z2.qiniup.com"
      :data="uploadParams"
      :on-format-error="addError"
      :on-success="addFileSuccess"
      :before-upload="beforeUpload"
    >
      <div style="padding: 20px 0">
        <Icon type="ios-cloud-upload" size="52" style="color: #3399ff"></Icon>
        <p>拖入上传</p>
      </div>
    </Upload>
    <!-- <button @click="zz">上传</button> -->
  </template>
  <script>
  export default {
    // props:['childEvent'],
    data(){
      return{
        uploadParams: {},
        avatarUrl: []
      }
    },
    methods: {
      onCancle(){
        this.$emit("closeEdit")
      },
      addFileSuccess(request, file, list) {
        // console.log(file, list, request.key, "上传成功");
        // console.log(request.url);
        this.avatarUrl.push(request.url);
        this.$emit("getUrl",this.avatarUrl)
        console.log(this.avatarUrl);
      },
      addError(request, file) {
        console.log(request, file);
        this.$Notice.warning({
          title: "格式错误",
          desc: "请上传png、jpg、jpeg格式文件",
        });
      },
      async beforeUpload(request) {
        let filename = new Date().getTime() + "_" + request.name;
        let data = await this.$axios.get(
          "http://unicloud.codecore.cn/admin/qiniuToken"
        );
        let token = data.data.token;
        this.uploadParams.token = token;
        // this.imgQiniuToken = token;
        // this.imgQiniuUrlPre = "moxiang";
        this.uploadParams.key = "moxiang/"+filename;
        return this.uploadParams
      },
      // zz(){
      //   console.log(this.avatarUrl);
      //   this.childEvent(this.avatarUrl)
      // }
    },
  };
  </script>